package controller;

import java.util.ArrayList;

import com.googlecode.grtframework.actuator.IServo;
import com.googlecode.grtframework.event.PotentiometerEvent;
import com.googlecode.grtframework.event.PotentiometerListener;
import com.googlecode.grtframework.sensor.IPotentiometer;

public class ServoController implements PotentiometerListener {

	private final ArrayList<IServo> servos;
	private final IPotentiometer pot;

	public ServoController(ArrayList<IServo> servos, IPotentiometer pot) {
		this.servos = servos;
		this.pot = pot;

	}

	@Override
	public void rotationChanged(PotentiometerEvent pev) {
		for (IServo s : servos) {
			s.setPosition(pev.getAngle());
		}
	}

	@Override
	public void rotationStarted(PotentiometerEvent pev) {

	}

	@Override
	public void rotationStopped(PotentiometerEvent pev) {

	}

	@Override
	public void startListening() {
		pot.addPotentiometerListener(this);
	}

	@Override
	public void stopListening() {
		pot.removePotentiometerListener(this);
	}

}
